#ifndef SEARCH_H_
#define SEARCH_H_

#include <unordered_map>
#include <vector>
#include "eval.h"

struct Solution {
    Coordinate from, to;
};

class Search {
public:
    Search(int maxLevel = 0);
    virtual ~Search();

    void SetMaxLevel(int maxLevel);
    Solution SearchNextMove(int step, const Positions & positions);

private:
    static const int DIRX[4];
    static const int DIRY[4];

    Eval *eval;
    int mMaxLevel;
    int mColor;

    bool IsEnemy(int piece) const;
    bool InRange(int x, int y) const;
    bool InRange(const Coordinate & c) const;

    bool TransformToBoard(Board board, const Positions & positions);
    std::vector<Coordinate> GetMovable(const Board board, Coordinate c);
    std::vector<Solution> GetAllMoves(const Board board, const Positions & positions);

    std::pair<Solution, bool> RandomMove(const Board board, const Positions & positions);
    std::pair<Solution, bool> CorrectMove(const Board board, const Positions & positions);
    int AlphaBeta(int depth, Board board, Positions & positions, bool isMaximizer, int alpha, int beta);
};


#endif
